﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.ServiceProxy
{
    public static class PubServiceProxyManager
    {
        private static CPPEI.Coolzon.Configuration.Client.ServiceConfig s_serviceConfig;

        static PubServiceProxyManager()
        {
            s_serviceConfig = Configuration.Client.Config.Host.GetServiceConfig("PublishService");
        }

        public static PubServiceRef.PublishServiceClient Create()
        {
            System.ServiceModel.Channels.Binding tcpBinding = new NetTcpBinding();
            (tcpBinding as NetTcpBinding).ReceiveTimeout = TimeSpan.FromSeconds(300);
            (tcpBinding as NetTcpBinding).SendTimeout = TimeSpan.FromSeconds(300);
            (tcpBinding as NetTcpBinding).Security.Mode = SecurityMode.None;
            (tcpBinding as NetTcpBinding).TransferMode = TransferMode.Streamed;
            (tcpBinding as NetTcpBinding).MaxBufferSize = 1024 * 1024 * 1024;
            (tcpBinding as NetTcpBinding).MaxReceivedMessageSize = 1024 * 1024 * 1024;
            EndpointAddress address = new EndpointAddress(string.Format("net.tcp://{0}:{1}/{2}/", s_serviceConfig.IP, s_serviceConfig.Port, s_serviceConfig.Path));

            PubServiceRef.PublishServiceClient client = new PubServiceRef.PublishServiceClient(tcpBinding, address);
            return client;
        }
    }
}
